﻿using System;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using DeveloperModule.Services;
using DeveloperModule.Controllers;

namespace DeveloperModule
{
    public class DeveloperModule : IModule
    {
        private readonly IRegionManager _regionManager;
        private readonly IUnityContainer _container;

        public DeveloperModule(IRegionManager regionManager, IUnityContainer container)
        {
            _regionManager = regionManager;
            _container = container;
        }

        public void Initialize()
        {
            // TODO: register views
            _container.RegisterType<Object, Views.UserSelectionView>(typeof(Views.UserSelectionView).Name);

            // register controllers
            _container.RegisterInstance<IUserSelectionController>(new UserSelectionController());

            // register services
            var sessionService = _container.Resolve<TimeSplicerModule.Security.ISessionService>();
            var userService = _container.Resolve<TimeSplicerModule.Services.IUserService>();
            var projectFactory = _container.Resolve<TimeSplicerModule.Factories.IProjectFactory>();
            var taskFactory = _container.Resolve<TimeSplicerModule.Factories.ITaskFactory>();
            var timestampFactory = _container.Resolve<TimeSplicerModule.Factories.ITimestampFactory>();
            var statusFactory = _container.Resolve<TimeSplicerModule.Factories.IStatusFactory>();


            var developerService = new DeveloperService(_container, userService, sessionService, projectFactory, taskFactory, timestampFactory, statusFactory);

            _container.RegisterInstance<IDeveloperService>(developerService);
        }
    }
}
